class UnionFind:
    def __init__(self, n):
        self.fa = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        if self.fa[x] != x:
            self.fa[x] = self.find(self.fa[x])
        return self.fa[x]

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x != root_y:
            self.fa[root_y] = root_x
            self.size[root_x] += self.size[root_y]


if __name__ == '__main__':
    N, D = map(int, input().split())
    countries = list(map(int, input().split()))
    uf_c = UnionFind(N)  # 代表同一个国家
    uf_not = UnionFind(N)  # 代表两人是一个国家且距离大于2
